<?php

/**
 * This is the model class for table "planet_detail".
 *
 * The followings are the available columns in table 'planet_detail':
 * @property integer $id
 * @property integer $planet_id
 * @property string $created
 * @property integer $status
 * @property integer $points
 * @property integer $worker
 * @property integer $manpower
 * @property integer $energy
 * @property integer $iron
 * @property integer $silicon
 * @property integer $carbon
 * @property integer $water
 * @property integer $oxygen
 * @property integer $hydrogen
 * @property integer $planet_center
 * @property integer $spaceport
 * @property integer $residence
 * @property integer $solar_park
 * @property integer $iron_mine
 * @property integer $silicon_mine
 * @property integer $carbon_mine
 * @property integer $derrick
 * @property integer $chemical_plant
 * @property integer $recycling_plant
 * @property integer $storage
 * @property integer $ship_factory
 * @property integer $weapon_factory
 * @property integer $research
 *
 * The followings are the available model relations:
 * @property Planet $planet
 */
class PlanetDetail extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PlanetDetail the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'planet_detail';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('planet_id, created', 'required'),
			array('planet_id, status, points, worker, manpower, energy, iron, silicon, carbon, water, oxygen, hydrogen, planet_center, spaceport, residence, solar_park, iron_mine, silicon_mine, carbon_mine, derrick, chemical_plant, recycling_plant, storage, ship_factory, weapon_factory, research', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, planet_id, created, status, points, worker, manpower, energy, iron, silicon, carbon, water, oxygen, hydrogen, planet_center, spaceport, residence, solar_park, iron_mine, silicon_mine, carbon_mine, derrick, chemical_plant, recycling_plant, storage, ship_factory, weapon_factory, research', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'planet' => array(self::BELONGS_TO, 'Planet', 'planet_id'),
		);
	}

  public function scopes()
  {
    return array(
      'active' => array(
        'condition' => 'status = 1',
      ),
    );
  }

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'planet_id' => 'Planet',
			'created' => 'Created',
			'status' => 'Status',
			'points' => 'Points',
			'worker' => 'Worker',
			'manpower' => 'Manpower',
			'energy' => 'Energy',
			'iron' => 'Iron',
			'silicon' => 'Silicon',
			'carbon' => 'Carbon',
			'water' => 'Water',
			'oxygen' => 'Oxygen',
			'hydrogen' => 'Hydrogen',
			'planet_center' => 'Planet Center',
			'spaceport' => 'Spaceport',
			'residence' => 'Residence',
			'solar_park' => 'Solar Park',
			'iron_mine' => 'Iron Mine',
			'silicon_mine' => 'Silicon Mine',
			'carbon_mine' => 'Carbon Mine',
			'derrick' => 'Derrick',
			'chemical_plant' => 'Chemical Plant',
			'recycling_plant' => 'Recycling Plant',
			'storage' => 'Storage',
			'ship_factory' => 'Ship Factory',
			'weapon_factory' => 'Weapon Factory',
			'research' => 'Research',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('planet_id',$this->planet_id);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('points',$this->points);
		$criteria->compare('worker',$this->worker);
		$criteria->compare('manpower',$this->manpower);
		$criteria->compare('energy',$this->energy);
		$criteria->compare('iron',$this->iron);
		$criteria->compare('silicon',$this->silicon);
		$criteria->compare('carbon',$this->carbon);
		$criteria->compare('water',$this->water);
		$criteria->compare('oxygen',$this->oxygen);
		$criteria->compare('hydrogen',$this->hydrogen);
		$criteria->compare('planet_center',$this->planet_center);
		$criteria->compare('spaceport',$this->spaceport);
		$criteria->compare('residence',$this->residence);
		$criteria->compare('solar_park',$this->solar_park);
		$criteria->compare('iron_mine',$this->iron_mine);
		$criteria->compare('silicon_mine',$this->silicon_mine);
		$criteria->compare('carbon_mine',$this->carbon_mine);
		$criteria->compare('derrick',$this->derrick);
		$criteria->compare('chemical_plant',$this->chemical_plant);
		$criteria->compare('recycling_plant',$this->recycling_plant);
		$criteria->compare('storage',$this->storage);
		$criteria->compare('ship_factory',$this->ship_factory);
		$criteria->compare('weapon_factory',$this->weapon_factory);
		$criteria->compare('research',$this->research);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}